<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * RefundTicket_model
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class RefundTicket_model extends MY_Model{
    public function __construct(){
            parent::__construct();
            $this->table_name = 'book_refundticket';
    }
    
    public function _getListPaymentMethod(){
        $payment_method = $this->getListPaymentMethod();
        unset($payment_method[4]);
        return $payment_method;
    }
    
    public function init_data($right){
		return array(
                               array(
						'name' => 'id',
						'label' => $this->lang->line('number'),
						'width' => '2%',
						'sort'  => 'DESC',
						'searchoptions' => false
				),
                                array(
						'name' => 'airline',
						'label' => $this->lang->line('airline'),
						'width' => '2%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'booking_place_code',
						'label' => $this->lang->line('booking_place_code').'/Số vé',
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'net_fare',
						'label' => $this->lang->line('net_fare').'(VNĐ)',
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'sale_fare',
						'label' => $this->lang->line('thuc-thu-cty').'(VNĐ)',
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'thuctra',
						'label' => $this->lang->line('thuc-tra-khach').'(VNĐ)',
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'note',
						'label' => $this->lang->line('note'),
						'width' => '15%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'booker',
						'label' => $this->lang->line('booker'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'status',
						'label' => $this->lang->line('status'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'lastupdated',
						'label' => $this->lang->line('lastupdated'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name'  => 'button',
						'width' => '5%',
						'sort'  => FALSE,
						'label'  => $right['add']==TRUE?'<div class="btn-group">
						<a style="width: 82px;" href="'.site_url('auth/refundTicket/index/add').'" class="btn btn btn-success">'.$this->lang->line('create').'</a>
						</div>':'',
						'searchoptions' => false
				)
		);
	}
	
	public function json_data($controller, $right){
		$this->datatables
		->select('tbl.id, tbl.airline, tbl.booking_place_code, tbl.net_fare,tbl.sale_fare,tbl.thuctra,tbl.lastupdated,tbl.status,tbl.note,usr.username AS booker')
		->from($this->table_name.' AS tbl')
                ->join('users AS usr','usr.id = tbl.owner');
                
                if($this->session->userdata['group_id'] == 79){//group payment
                    $this->datatables->where('tbl.status',0);//show hoan ve chua duyet
                }
                if($this->session->userdata['group_id'] == 78){//group booker
                    $this->datatables->where("tbl.owner",$this->session->userdata['user_id']);
                }
                
		$this->datatables->set_produce_output(false);
		$ouput = $datatables = $this->datatables->generate();
		unset($ouput['aaData']);
		$ouput['aaData'] = array();

		foreach($datatables['aaData'] as $item){
                        $booking_place_code = json_decode($item['booking_place_code']);
			$ouput['aaData'][] = array(
                            $item['id'],
                            $item['airline'],
                            implode(", ",$booking_place_code),
                            $this->bookinglib->my_number_format($item['net_fare'],2, ',', ','),
                            $this->bookinglib->my_number_format($item['sale_fare'],2, ',', ','),
                            $this->bookinglib->my_number_format($item['thuctra'],2, ',', ','),
                            $item['note'],
                            $item['booker'],
                            ($item['status']==1)?$this->lang->line('approved'):$this->lang->line('unapproved'),
                            date("d-m-Y H:i:s",strtotime($item['lastupdated'])),
                            ($item['status']==1)?'':$this->add_button_public($controller, $right, $item)
			);
		}
	
		return json_encode($ouput);
	}
        
}